home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Linux / SLAX 6.0.8 / slax-6.0.8.iso / slax / base / 006-devel.lzm / usr / include / kfiletreeview.h < prev    next >
Encoding:
C/C++ Source or Header  |  2007-01-15  |  8.7 KB  |  274 lines

  1. /* This file is part of the KDE project
  2.    Copyright (C) 2000 David Faure <faure@kde.org>
  3.                  2000 Carsten Pfeiffer <pfeiffer@kde.org>
  4.          2002 Klaas Freitag <freitag@suse.de>
  5.  
  6.    This library is free software; you can redistribute it and/or
  7.    modify it under the terms of the GNU Library General Public
  8.    License version 2 as published by the Free Software Foundation.
  9.  
  10.    This library is distributed in the hope that it will be useful,
  11.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13.    Library General Public License for more details.
  14.  
  15.    You should have received a copy of the GNU Library General Public License
  16.    along with this library; see the file COPYING.LIB.  If not, write to
  17.    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  18.    Boston, MA 02110-1301, USA.
  19. */
  20.  
  21. #ifndef kfile_tree_view_h
  22. #define kfile_tree_view_h
  23.  
  24. #include <qmap.h>
  25. #include <qpoint.h>
  26. #include <qpixmap.h>
  27. #include <qstrlist.h>
  28. #include <qtooltip.h>
  29.  
  30. #include <klistview.h>
  31. #include <kdirnotify.h>
  32. #include <kio/job.h>
  33. #include <kfiletreeviewitem.h>
  34. #include <kfiletreebranch.h>
  35.  
  36. class QTimer;
  37.  
  38.  
  39.  
  40. class KIO_EXPORT KFileTreeViewToolTip : public QToolTip
  41. {
  42. public:
  43.     KFileTreeViewToolTip( QListView *view ) : QToolTip( view ), m_view( view ) {}
  44.  
  45. protected:
  46.     virtual void maybeTip( const QPoint & );
  47.  
  48. private:
  49.     QListView *m_view;
  50. };
  51.  
  52.  
  53. /**
  54.  * The filetreeview offers a treeview on the file system which behaves like
  55.  * a QTreeView showing files and/or directories in the file system.
  56.  *
  57.  * KFileTreeView is able to handle more than one URL, represented by
  58.  * KFileTreeBranch.
  59.  *
  60.  * Typical usage:
  61.  * 1. create a KFileTreeView fitting in your layout and add columns to it
  62.  * 2. call addBranch to create one or more branches
  63.  * 3. retrieve the root item with KFileTreeBranch::root() and set it open
  64.  *    if desired. That starts the listing.
  65.  */
  66. class KIO_EXPORT KFileTreeView : public KListView
  67. {
  68.     Q_OBJECT
  69. public:
  70.     KFileTreeView( QWidget *parent, const char *name = 0 );
  71.     virtual ~KFileTreeView();
  72.  
  73.     /**
  74.      * @return the current (i.e. selected) item
  75.      */
  76.     KFileTreeViewItem * currentKFileTreeViewItem() const;
  77.  
  78.    /**
  79.     * @return the URL of the current selected item.
  80.     */
  81.     KURL currentURL() const;
  82.  
  83.    /**
  84.     *  Adds a branch to the treeview item.
  85.     *
  86.     *  This high-level function creates the branch, adds it to the treeview and
  87.     *  connects some signals. Note that directory listing does not start until
  88.     *  a branch is expanded either by opening the root item by user or by setOpen
  89.     *  on the root item.
  90.     *
  91.     *  @returns a pointer to the new branch or zero
  92.     *  @param path is the base url of the branch
  93.     *  @param name is the name of the branch, which will be the text for column 0
  94.     *  @param showHidden says if hidden files and directories should be visible
  95.     */
  96.    KFileTreeBranch* addBranch( const KURL &path, const QString& name, bool showHidden = false );
  97.  
  98.    /**
  99.     *  same as the function above but with a pixmap to set for the branch.
  100.     */
  101.    virtual KFileTreeBranch* addBranch( const KURL &path, const QString& name ,
  102.                        const QPixmap& pix, bool showHidden = false  );
  103.  
  104.    /**
  105.     *  same as the function above but letting the user create the branch.
  106.     */
  107.    virtual KFileTreeBranch* addBranch( KFileTreeBranch * );
  108.  
  109.    /**
  110.     *  removes the branch from the treeview.
  111.     *  @param branch is a pointer to the branch
  112.     *  @returns true on success.
  113.     */
  114.    virtual bool removeBranch( KFileTreeBranch *branch );
  115.  
  116.    /**
  117.     *  @returns a pointer to the KFileTreeBranch in the KFileTreeView or zero on failure.
  118.     *  @param searchName is the name of a branch
  119.     */
  120.    KFileTreeBranch *branch( const QString& searchName );
  121.  
  122.  
  123.    /**
  124.     *  @returns a list of pointers to all existing branches in the treeview.
  125.     **/
  126.    KFileTreeBranchList& branches();
  127.  
  128.    /**
  129.     *  set the directory mode for branches. If true is passed, only directories will be loaded.
  130.     *  @param branch is a pointer to a KFileTreeBranch
  131.     */
  132.    virtual void setDirOnlyMode( KFileTreeBranch *branch, bool );
  133.  
  134.    /**
  135.     * searches a branch for a KFileTreeViewItem identified by the relative url given as
  136.     * second parameter. The method adds the branches base url to the relative path and finds
  137.     * the item.
  138.     * @returns a pointer to the item or zero if the item does not exist.
  139.     * @param brnch  is a pointer to the branch to search in
  140.     * @param relUrl is the branch relativ url
  141.     */
  142.    KFileTreeViewItem *findItem( KFileTreeBranch* brnch, const QString& relUrl );
  143.  
  144.    /**
  145.     * see method above, differs only in the first parameter. Finds the branch by its name.
  146.     */
  147.    KFileTreeViewItem *findItem( const QString& branchName, const QString& relUrl );
  148.  
  149.    /**
  150.     * @returns a flag indicating if extended folder pixmaps are displayed or not.
  151.     */
  152.    bool showFolderOpenPixmap() const { return m_wantOpenFolderPixmaps; };
  153.  
  154. public slots:
  155.  
  156.    /**
  157.     * set the flag to show 'extended' folder icons on or off. If switched on, folders will
  158.     * have an open folder pixmap displayed if their children are visible, and the standard
  159.     * closed folder pixmap (from mimetype folder) if they are closed.
  160.     * If switched off, the plain mime pixmap is displayed.
  161.     * @param showIt = false displays mime type pixmap only
  162.     */
  163.    virtual void setShowFolderOpenPixmap( bool showIt = true )
  164.       { m_wantOpenFolderPixmaps = showIt; }
  165.  
  166. protected:
  167.    /**
  168.     * @returns true if we can decode the drag and support the action
  169.     */
  170.  
  171.    virtual bool acceptDrag(QDropEvent* event) const;
  172.     virtual QDragObject * dragObject();
  173.  
  174.     virtual void startAnimation( KFileTreeViewItem* item, const char * iconBaseName = "kde", uint iconCount = 6 );
  175.     virtual void stopAnimation( KFileTreeViewItem* item );
  176.     virtual void contentsDragEnterEvent( QDragEnterEvent *e );
  177.     virtual void contentsDragMoveEvent( QDragMoveEvent *e );
  178.     virtual void contentsDragLeaveEvent( QDragLeaveEvent *e );
  179.     virtual void contentsDropEvent( QDropEvent *ev );
  180.  
  181. protected slots:
  182.     virtual void slotNewTreeViewItems( KFileTreeBranch*,
  183.                        const KFileTreeViewItemList& );
  184.  
  185.     virtual void slotSetNextUrlToSelect( const KURL &url )
  186.       { m_nextUrlToSelect = url; }
  187.  
  188.     virtual QPixmap itemIcon( KFileTreeViewItem*, int gap = 0 ) const;
  189.  
  190. private slots:
  191.     void slotExecuted( QListViewItem * );
  192.     void slotExpanded( QListViewItem * );
  193.     void slotCollapsed( QListViewItem *item );
  194.  
  195.     void slotSelectionChanged();
  196.  
  197.     void slotAnimation();
  198.  
  199.     void slotAutoOpenFolder();
  200.  
  201.     void slotOnItem( QListViewItem * );
  202.     void slotItemRenamed(QListViewItem*, const QString &, int);
  203.  
  204.    void slotPopulateFinished( KFileTreeViewItem* );
  205.  
  206.  
  207. signals:
  208.  
  209.    void onItem( const QString& );
  210.    /* New signals if you like it ? */
  211.    void dropped( QWidget*, QDropEvent* );
  212.    void dropped( QWidget*, QDropEvent*, KURL::List& );
  213.    void dropped( KURL::List&, KURL& );
  214.    // The drop event allows to differentiate between move and copy
  215.    void dropped( QWidget*, QDropEvent*, KURL::List&, KURL& );
  216.  
  217.    void dropped( QDropEvent *e, QListViewItem * after);
  218.    void dropped(KFileTreeView *, QDropEvent *, QListViewItem *);
  219.    void dropped(QDropEvent *e, QListViewItem * parent, QListViewItem * after);
  220.    void dropped(KFileTreeView *, QDropEvent *, QListViewItem *, QListViewItem *);
  221.  
  222. protected:
  223.    KURL m_nextUrlToSelect;
  224.  
  225.  
  226. private:
  227.     // Returns whether item is still a valid item in the tree
  228.     bool isValidItem( QListViewItem *item);
  229.     void clearTree();
  230.  
  231.  
  232.    /* List that holds the branches */
  233.     KFileTreeBranchList m_branches;
  234.  
  235.  
  236.     struct AnimationInfo
  237.     {
  238.         AnimationInfo( const char * _iconBaseName, uint _iconCount, const QPixmap & _originalPixmap )
  239.             : iconBaseName(_iconBaseName), iconCount(_iconCount), iconNumber(1), originalPixmap(_originalPixmap) {}
  240.         AnimationInfo() : iconCount(0) {}
  241.         QCString iconBaseName;
  242.         uint iconCount;
  243.         uint iconNumber;
  244.         QPixmap originalPixmap;
  245.     };
  246.     typedef QMap<KFileTreeViewItem *, AnimationInfo> MapCurrentOpeningFolders;
  247.     MapCurrentOpeningFolders m_mapCurrentOpeningFolders;
  248.  
  249.  
  250.     QTimer *m_animationTimer;
  251.  
  252.     QPoint m_dragPos;
  253.     bool m_bDrag;
  254.  
  255.    bool m_wantOpenFolderPixmaps; // Flag weather the folder should have open-folder pixmaps
  256.  
  257.     QListViewItem *m_currentBeforeDropItem; // The item that was current before the drag-enter event happened
  258.     QListViewItem *m_dropItem; // The item we are moving the mouse over (during a drag)
  259.     QStrList m_lstDropFormats;
  260.    QPixmap  m_openFolderPixmap;
  261.     QTimer *m_autoOpenTimer;
  262.  
  263.     KFileTreeViewToolTip m_toolTip;
  264.  
  265.  
  266. protected:
  267.    virtual void virtual_hook( int id, void* data );
  268. private:
  269.    class KFileTreeViewPrivate;
  270.    KFileTreeViewPrivate *d;
  271. };
  272.  
  273. #endif
  274.